package com.duoqin.common.data.remote;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class ApiClient {
    public static final String BASE_URL = "http://service.duoqin.com/"; // "http://120.92.212.99:8888/";
    public static final String APP_SERVER_URL = "http://service.duoqin.com/"; // "http://service.caredear.cn:8888/";
    private static final String VCARD_BASE_URL = "http://assist.duoqin.com/vcardserver/"; // http://111.231.77.250:8888/";
    private static final String REMOTE_SERVICE_BASE_URL = "http://guard.duoqin.com"; // "http://test.duoqin.com/"
    private static Retrofit retrofit = null;
    private static Retrofit appRetrofit = null;
    private static Retrofit vcardRetrofit = null;
    private static Retrofit feedbackRetrofit = null;
    private static Retrofit remoteServiceRetrofit = null;
    private static final String TEMP_FEEEDBACK_URL = "http://192.168.1.4:8999";

    private ApiClient() {
    }

    public static Retrofit getClient() {
        if (retrofit == null) {
            OkHttpClient okHttpClient = new OkHttpClient().newBuilder().build();
            retrofit = new Retrofit.Builder()
                    .baseUrl(BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .client(okHttpClient)
                    .build();
        }

        return retrofit;
    }

    public static Retrofit getFeedbackClient(){
        if (feedbackRetrofit == null) {
            OkHttpClient okHttpClient = new OkHttpClient().newBuilder().build();
            feedbackRetrofit = new Retrofit.Builder()
                    .baseUrl(TEMP_FEEEDBACK_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .client(okHttpClient)
                    .build();
        }

        return feedbackRetrofit;
    }

    public static Retrofit getAppClient() {
        if (appRetrofit == null) {
            OkHttpClient okHttpClient = new OkHttpClient().newBuilder().build();
            appRetrofit = new Retrofit.Builder()
                    .baseUrl(APP_SERVER_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .client(okHttpClient)
                    .build();
        }

        return appRetrofit;
    }

    public static Retrofit getvCardClient() {
        if (vcardRetrofit == null) {
            OkHttpClient okHttpClient = new OkHttpClient()
                    .newBuilder()
                    .build();
            vcardRetrofit = new Retrofit.Builder()
                    .baseUrl(VCARD_BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .client(okHttpClient)
                    .build();
        }

        return vcardRetrofit;
    }

    public static Retrofit getRemoteServiceClient() {
        if (remoteServiceRetrofit == null) {
            OkHttpClient okHttpClient = new OkHttpClient().newBuilder().build();
            remoteServiceRetrofit = new Retrofit.Builder()
                    .baseUrl(REMOTE_SERVICE_BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .client(okHttpClient)
                    .build();
        }

        return remoteServiceRetrofit;
    }
}